package cn.stylefeng.guns.sys.modular.dataAnalyse.service.impl;

import cn.stylefeng.guns.sys.modular.dataAnalyse.mapper.DataAnalyseMapper;
import cn.stylefeng.guns.sys.modular.dataAnalyse.service.DataAnalyseService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DataAnalyseServiceImpl implements DataAnalyseService {
    @Autowired
    private DataAnalyseMapper dataAnalyseMapper;

    @Override
    public int queryProblemTotal() {
        List<Integer> list = this.dataAnalyseMapper.queryProblemTotalInfo();
        int returnInt = 0;
        for (int i = 0; i < list.size(); i++) {
            returnInt = returnInt + list.get(i);
        }
        return returnInt;
    }

    @Override
    public List<String> queryAllDepartmentInfo() {
        return this.dataAnalyseMapper.queryAllDepartment();
    }

    @Override
    public JSONObject queryDataByDepartmentInfo() {
        JSONObject obj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        List<String> list = this.dataAnalyseMapper.queryAllDepartment();
        obj.put("dept", list);
        int deptTotal = 0;
        for (int i = 0; i < list.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            List<Integer> list1 = this.dataAnalyseMapper.queryDataByDepartment(list.get(i));
            for (int j = 0; j < list1.size(); j++) {
                deptTotal = deptTotal + list1.get(j);
            }
            jsonObject.put("value", deptTotal);
            jsonObject.put("name", list.get(i));
            jsonArray.add(jsonObject);
        }
        obj.put("data", jsonArray);
        return obj;
    }
}
